/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__zookeeper_get_str.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include <zookeeper/zookeeper_core.h>
#include <zookeeper/zookeeper_common.h>
#include <zookeeper/zookeeper_request.h>
#include <apmtest_comm.h>
#include <zookeeper/config.h>

int __zookeeper_parse_delete(Frbyte_Packet *p_st_data
                            , L7_req_zookeeper *p_st_req);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    L7_req_zookeeper st_req;
    memset(&st_req, 0x0,  sizeof(st_req));
    Frbyte_Packet *p_st_data = NULL;
    Frlist_node *p_st_node = NULL;
    Frvar_field *p_st_field = NULL;


    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x04\x31\x32\x33\x34\x00\x00\x00\x04", 12);

    i_ret = __zookeeper_parse_delete(p_st_data, &st_req);

    p_st_node = FRLIST_FIRST_NODE(&st_req.st_data_lst);
    p_st_field = (Frvar_field *)FRLIST_GET_NODE_DATA(p_st_node);
    CU_ASSERT_STRING_EQUAL(p_st_field->p_field_name, "path");
    CU_ASSERT_STRING_EQUAL(p_st_field->field_value.p_value, "1234");
    CU_ASSERT_EQUAL(p_st_field->em_data_type, FRSTRING);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);

    frlist_remove_all(&st_req.st_data_lst, frbindata_node_free);
    bytebuff_free(&p_st_data);

    return;
}

static void __case2(void)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    L7_req_zookeeper st_req;
    memset(&st_req, 0x0,  sizeof(st_req));
    Frbyte_Packet *p_st_data = NULL;


    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x04\x31\x32\x33\x34\x00\x00\x00\x04", 11);

    i_ret = __zookeeper_parse_delete(p_st_data, &st_req);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    frlist_remove_all(&st_req.st_data_lst, frbindata_node_free);
    bytebuff_free(&p_st_data);

    return;
}

static void __case3(void)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    L7_req_zookeeper st_req;
    memset(&st_req, 0x0,  sizeof(st_req));
    Frbyte_Packet *p_st_data = NULL;


    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x04\x31\x32\x33\x34\x00\x00\x00\x04", 7);

    i_ret = __zookeeper_parse_delete(p_st_data, &st_req);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    bytebuff_free(&p_st_data);

    return;
}


int add_suite_zookeeper_parse_delete(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __zookeeper_parse_delete()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL
        )
        return FR_FAIL;

    return FR_SUCC;
}
